package org.wattdepot.cli.processor;

import java.util.List;
import org.wattdepot.cli.command.WattPowerStats;

/**
 * Parses the powerstats command.
 * 
 * @author Kendyll Doi
 * @author Kimberly Heu
 *
 */
public class PowerStatsCommand extends CommandLineInterface implements WattDepotCliCommand {
  
  /**
   * Parses the powerstats command.
   * 
   * @param args The user's inputed arguments
   * @return The results of running the powerstats command
   */
  public String doCommand(List<String> args) {
    StringBuffer buf = new StringBuffer(500); // Buffer to store the results
    String output = ""; // String with contents to return
    
    // Check the number of arguments given
    if (args.size() == 9) {
      
      // Check the syntax of the arguments
      if ((args.get(1).equalsIgnoreCase("generated") || args.get(1).equalsIgnoreCase("consumed"))
          && args.get(3).equalsIgnoreCase("day") 
          && args.get(5).equalsIgnoreCase("sampling-interval")
          && args.get(7).equalsIgnoreCase("statistic")
          && (args.get(8).equalsIgnoreCase("min") || args.get(8).equalsIgnoreCase("max") 
              || args.get(8).equalsIgnoreCase("average"))) {
        buf.append(WattPowerStats.wattListPowerDay(args.get(1), args.get(2), args.get(4), 
            args.get(6), args.get(8), client));
      }
      else {
        // Incorrect syntax for the arguments
        buf.append("Incorrect syntax for power command.");
      }
    }
    else {
      // Incorrect number of arguments; give error message
      buf.append("Incorrect number of arguments for power command.");
    }
    
    // Convert buffer to string and return
    output = buf.toString();
    return output;
  }

}
